#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 1e6 + 10;

int n, fa[22][N], dep[N], p[N];
ll ans1, ans2;
vec G[N];

void dfs(int x, int p) {
	dep[x] = dep[p] + 1; fa[0][x] = p; rep(i, 1, 20) fa[i][x] = fa[i - 1][fa[i - 1][x]];
	for(auto y : G[x]) if(y ^ p) dfs(y, x);
}

int lca(int x, int y) {
	if(dep[x] < dep[y]) swap(x, y);
	per(i, 20, 0) if(dep[fa[i][x]] >= dep[y]) x = fa[i][x];
	if(x == y) return x;
	per(i, 20, 0) if(fa[i][x] != fa[i][y]) x = fa[i][x], y = fa[i][y];
	return fa[0][x];
}
int dis(int x, int y) { return dep[x] + dep[y] - 2 * dep[lca(x, y)]; }

bool vis[N];

bool checkp() { rep(i, 1, n) vis[i] = false; rep(i, 1, n) if(p[i] >= 1 && p[i] <= n && p[i] != i) vis[p[i]] = true; else return cerr << i << " " << p[i] << " INValid " << endl, 0; rep(i, 1, n) if(!vis[i]) return 0; return 1; }
void readp() { rep(i, 1, n) p[i] = in; if(!checkp()) puts("WA. p is not ok!"), exit(-1); }
ll calcp() {
	ll res = 0;
	rep(i, 1, n)  res += dis(i, p[i]);
	cerr << res << " ";
	return res;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin); 
#endif
	n = in; rep(i, 2, n) { int u = in, v = in; G[u].eb(v); G[v].eb(u); }
	dfs(1, 0);
	freopen("1.out", "r", stdin);
	ans1 = lin, ans2 = lin;
	readp(); if(calcp() != ans1) puts("WA. dis1 is not eq!"), exit(-1);
	readp(); if(calcp() != ans2) puts("WA. dis2 is not eq!"), exit(-1);
	puts("ok"); return 0;
}
